package com.abvnet.project.water.project.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.project.water.project.domain.ProjectPharm;
import com.abvnet.project.water.project.service.IProjectMicrobialService;
import com.abvnet.project.water.project.service.IProjectPharmService;
import com.abvnet.project.water.sewage.service.ISewageFlowService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/project/projectPharm")
public class ProjectPharmController extends BaseController {

    private String prefix = "project/projectInfo";

    @Autowired
    private IProjectPharmService projectPharmService;

    @Autowired
    private IProjectMicrobialService projectMicrobialService;

    @Autowired
    private ISewageFlowService sewageFlowService;

    @GetMapping("/edit/{projectId}")
    public String edit(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("sfList", sewageFlowService.selectSewageFlowListByProjectId(projectId));
        mmap.put("csList", projectMicrobialService.selectCsList());
        mmap.put("phosList", projectMicrobialService.selectPhosList());
        mmap.put("flocList", projectMicrobialService.selectFlocList());
        mmap.put("oxidList", projectMicrobialService.selectOxidList());
        mmap.put("otherList", projectMicrobialService.selectOtherList());
        mmap.put("projectPharm", projectPharmService.selectProjectPharmByProjectId(projectId));
        return prefix + "/pharm";
    }

    @Log(title = "药剂使用情况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectPharm projectPharm) {
        return toAjax(projectPharmService.updateProjectPharm(projectPharm));
    }
}
